function [ vectorOut, lastOut ] = moveShip( vectorIn, lastIn, step ,p,n)
%MOVESHIP: Calculates the new vector for the ship
% vectorIn: current ship vector
% lastIn: last
% step: current time-step; counts the number of ships moves
% p: probability to go same direction; 1-np= probability to go back
% n


%First step: Random Point among the n+1 is choosen
if(step==0) 
  r=(n+1)*rand(1);            %choose a number between '0' and 'n+1'
  r=floor(r);                 %r becomes integer: 0, 1, 2, ..., n
  vectorOut=r;                   %vector receives the first position
  lastOut=vectorOut(end);
else

    a=rand(1);
    if a>1-n*p                      %same direction (n possibilities)
       text='same direction';
        r=n*rand(1);                %choose a number between '0' and 'n'
        r=ceil(r)  ;                %r becomes integer: 1, 2, ..., n
        vari=lastIn+r;
        vari=mod(vari,n+1);
        if isempty(vectorIn)
            [vectorOut, lastOut]=moveahead(vectorIn, vari);
        else
            if vectorIn(end)==vari
                [vectorOut, lastOut]=moveback(vectorIn);
            else 
                [vectorOut, lastOut]=moveahead(vectorIn, vari);
            end
        end
    else                            %go back (1 possibility)
        text='go back';
        if isempty(vectorIn)
            vari=lastIn;
            [vectorOut, lastOut] =moveahead(vectorIn, vari);

        else
            if vectorIn(end)==lastIn
                [vectorOut, lastOut] =moveback(vectorIn);
            else
                vari=lastIn;
                [vectorOut, lastOut] =moveahead(vectorIn, vari);

            end
        end
    end

    end
end

